feat(pass-extension): add autofill keyboard shortcut command - #481
feat(pass-extension): add autofill keyboard shortcut command#481yuribodo wants to merge 1666 commits into
Conversation
i18n(weekly-mr:app): Upgrade translations from crowdin (2d51304). for webapps See merge request web/clients!25193
Add support for system groups See merge request web/clients!25054
Extracting reused withTimeout to package/meet/utils See merge request web/clients!25060
Disable auto-complete on chat See merge request web/clients!25115
Scopes usernames with bdi See merge request web/clients!25117
fix(account): remove access check in categories settings See merge request web/clients!25198
Do not scroll element in view when changing page See merge request web/clients!25197
Rework byoe access check See merge request web/clients!25202
[REALTIME-240] Homepage SDK - folder events See merge request web/clients!25110
i18n(weekly-mr:app): Upgrade translations from crowdin (53310fd). for webapps See merge request web/clients!25210
Fix upsell path See merge request web/clients!25217
Sheets: Fix issue with settings dialog menu item See merge request web/clients!25218
115579e to
b6fd253
Compare
The Ctrl+Shift+U shortcut opens the dropdown with autofocused:false, so neither the page field nor the iframe receives keyboard focus. Expose requestFocus() on the dropdown that reuses the existing focus-lock bypass, and call it once the dropdown is visible so the suggestions can be reached from the keyboard.
…keys Wire useDropdownArrowNavigation + useHotkeys (bound to the iframe document) in the login view so the suggestions can be moved through with the arrow keys, selected with Enter, and dismissed with Escape. Highlight the focused item in the injected dropdown styles.
b9a9fb0 to
d639fe2
Compare
|
Hi @nguyenkims, I agree with your point having to reach for the mouse to pick a login kind of defeats the purpose of a keyboard shortcut. Based on that, I made some adjustments to the PR Just like you said, once the dropdown is shown you can now select a login entirely from the keyboard, with the up/down arrow keys I also rebased on the latest main so the diff is clean now. Let me know if you'd prefer different key bindings |
25168a8 to
97c88ca
Compare
| if (command === 'autofill') { | ||
| const [tab] = await browser.tabs.query({ active: true, currentWindow: true }); | ||
| if (tab?.id != null) { | ||
| browser.tabs.sendMessage(tab.id, backgroundMessage({ type: WorkerMessageType.AUTOFILL_TRIGGER })).catch(noop); |
There was a problem hiding this comment.
We recently added support for autofilling iframe fields as well (will be released in 1.38.0). This trigger will end up only broadcasting to the top-frame. We could iterate through all frames (starting from the top-level one) until we have a match and early exit here. It would require WorkerMessageType.AUTOFILL_TRIGGER's responses to carry a result.
| import { WorkerMessageType } from 'proton-pass-extension/types/messages'; | ||
|
|
||
| jest.mock('@proton/pass/lib/globals/browser', () => ({ | ||
| tabs: { |
There was a problem hiding this comment.
You can use (and/or augment) the applications/pass-extension/src/__mocks__/webextension-polyfill/index.ts global mocks here
| /** Only arm the field action-trap when the anchor field is the active element — i.e. the | ||
| * focus-recovery scenario. The shortcut flow opens the dropdown without focusing the field, | ||
| * so arming it there would needlessly suppress the field's normal autofocus dropdown. */ | ||
| if (anchor.current?.type === 'field' && isActiveElement(anchor.current.field.element)) { |
There was a problem hiding this comment.
For your use-case : could we rather drill a boolean flag down onWillFocus & onFocusRequest rather than relying on an active element check here ? The reason being : by-passing focus-traps is time-sensitive and the document.activeElement may be stale when onWillFocus triggers from an actual dropdown initiated focus request (but not through your new exposed handle).
| const onAutofillTrigger: FrameMessageHandler<WorkerMessageType.AUTOFILL_TRIGGER> = withContext(async (ctx) => { | ||
| const dropdown = ctx?.service.inline.dropdown; | ||
| const fields = ctx?.service.formManager.getFields(); | ||
| const loginField = fields?.find((field) => field.action?.type === DropdownAction.AUTOFILL_LOGIN); | ||
|
|
||
| if (!dropdown || !loginField) return; | ||
|
|
||
| dropdown.toggle({ | ||
| type: 'field', | ||
| action: DropdownAction.AUTOFILL_LOGIN, | ||
| autofocused: false, | ||
| autofilled: loginField.autofilled !== null, | ||
| field: loginField, | ||
| }); | ||
|
|
||
| /** Keyboard-only flow: once the dropdown is visible, move keyboard focus into it | ||
| * so the user can navigate the login suggestions with the arrow keys and select | ||
| * one with Enter — without touching the mouse. Unlike the focus-on-field flow, | ||
| * the shortcut opens the dropdown with `autofocused: false`, so nothing has moved | ||
| * focus into the iframe yet. */ | ||
| await waitUntil(() => dropdown.getState().then(({ visible }) => visible), 25, DROPDOWN_AUTOFOCUS_TIMEOUT) |
There was a problem hiding this comment.
There is a small type error when running yarn check-types inside applications/pass-extension, this shouldn't be async:
| const onAutofillTrigger: FrameMessageHandler<WorkerMessageType.AUTOFILL_TRIGGER> = withContext(async (ctx) => { | |
| const dropdown = ctx?.service.inline.dropdown; | |
| const fields = ctx?.service.formManager.getFields(); | |
| const loginField = fields?.find((field) => field.action?.type === DropdownAction.AUTOFILL_LOGIN); | |
| if (!dropdown || !loginField) return; | |
| dropdown.toggle({ | |
| type: 'field', | |
| action: DropdownAction.AUTOFILL_LOGIN, | |
| autofocused: false, | |
| autofilled: loginField.autofilled !== null, | |
| field: loginField, | |
| }); | |
| /** Keyboard-only flow: once the dropdown is visible, move keyboard focus into it | |
| * so the user can navigate the login suggestions with the arrow keys and select | |
| * one with Enter — without touching the mouse. Unlike the focus-on-field flow, | |
| * the shortcut opens the dropdown with `autofocused: false`, so nothing has moved | |
| * focus into the iframe yet. */ | |
| await waitUntil(() => dropdown.getState().then(({ visible }) => visible), 25, DROPDOWN_AUTOFOCUS_TIMEOUT) | |
| const onAutofillTrigger: FrameMessageHandler<WorkerMessageType.AUTOFILL_TRIGGER> = withContext((ctx) => { | |
| const dropdown = ctx?.service.inline.dropdown; | |
| const fields = ctx?.service.formManager.getFields(); | |
| const loginField = fields?.find((field) => field.action?.type === DropdownAction.AUTOFILL_LOGIN); | |
| if (!dropdown || !loginField) return; | |
| dropdown.toggle({ | |
| type: 'field', | |
| action: DropdownAction.AUTOFILL_LOGIN, | |
| autofocused: false, | |
| autofilled: loginField.autofilled !== null, | |
| field: loginField, | |
| }); | |
| /** Keyboard-only flow: once the dropdown is visible, move keyboard focus into it | |
| * so the user can navigate the login suggestions with the arrow keys and select | |
| * one with Enter — without touching the mouse. Unlike the focus-on-field flow, | |
| * the shortcut opens the dropdown with `autofocused: false`, so nothing has moved | |
| * focus into the iframe yet. */ | |
| void waitUntil(() => dropdown.getState().then(({ visible }) => visible), 25, DROPDOWN_AUTOFOCUS_TIMEOUT) |
Note that my suggestion may be changed if you implement #481 (comment)
6e496e5 to
bfa5069
Compare
896ff9e to
06694ac
Compare

Summary
Adds a keyboard shortcut to trigger autofill in the Proton Pass browser extension, as discussed and approved in #453.
autofillcommand in Chrome and Firefox manifests withCtrl+Shift+Uas the default shortcutAUTOFILL_TRIGGERmessage to the active tab's content scriptCloses #453
Changes
manifest-chrome.json"autofill"command entrymanifest-firefox.json"autofill"command entrysrc/types/messages.tsAUTOFILL_TRIGGERtoWorkerMessageTypeenumsrc/lib/extension/commands.ts"autofill"commandsrc/lib/extension/commands.spec.tssrc/app/content/services/autofill/autofill.service.tsAUTOFILL_TRIGGERhandler usingwithContextpatternHow it works
Ctrl+Shift+Ubrowser.commands.onCommandfires in the background scriptAUTOFILL_TRIGGERviabrowser.tabs.sendMessageFrameMessageBrokerreceives the messageDropdownAction.AUTOFILL_LOGINviaformManager.getFields()inline.dropdown.toggle()If no login field is detected on the page, the shortcut is a no-op.
Design decisions
Default shortcut
Ctrl+Shift+U: Chosen to avoid conflicts with existing commands (Ctrl+Shift+Xfor popup,Ctrl+Shift+Lfor larger window). The industry standard for autofill isCtrl+Shift+L(used by Bitwarden and LastPass). If the team is open to it, reassigningCtrl+Shift+Lfromopen-larger-windowtoautofillin a follow-up would align with user expectations from competing password managers.Dropdown approach (not direct autofill): Opens the dropdown instead of auto-filling the top match. This is safer, gives the user control when multiple credentials match, and reuses the existing dropdown infrastructure with minimal new code.
Safari excluded: Safari does not support the
browser.commandsAPI. The command listener is already gated byBUILD_TARGET !== 'safari'inworker/index.ts.Test plan
handleExtensionCommand(4 tests passing):open-larger-windowcommandAUTOFILL_TRIGGERto active tab forautofillcommandCtrl+Shift+Uon a login page → dropdown opens on first login fieldCtrl+Shift+Uon a page with no login form → nothing happensCtrl+Shift+XandCtrl+Shift+Lstill work as before